<?php

namespace App\Services\ExchangeBalance;

use App\Models\User;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class ExchangeBalance
{
	/**
	 * @var User
	 */
	protected $user;

	/**
	 * @var User
	 */

	protected $apples = 0;

	public function __construct(User $user, $apples)
	{
		$this->user = $user;
		$this->apples = $apples;
	}

	protected function transfer()
	{
		DB::transaction(function () {
			account_apples($this->user)->minusApplesExchangeBalances($this->apples,[]);
			$banlances = (string)big_decimal($this->apples)->multipliedBy(cs("sale")->apple_actual_price);

			account_balances($this->user)->plusExchangeBalances($banlances, []);
		});
	}

	public function apply()
	{

		$this->transfer();
	}
}
